package com.CGFrame.struts.bean.unit;

import java.util.Iterator;
import java.util.LinkedHashSet;

import com.CGFrame.struts.POJOs.Shot;
import com.CGFrame.struts.POJOs.Shotgroup;

public class ShotGroupBean {
	private Shotgroup shotGroup; 
	public ShotGroupBean(Shotgroup shotGroup)
	{
		this.shotGroup = shotGroup;
	}
	public LinkedHashSet getAllShots()
	{
		LinkedHashSet lin_AllShots =null;
		lin_AllShots = this.getAllShots(this.shotGroup);
		return lin_AllShots;
	}
	private LinkedHashSet getAllShots(Shotgroup m_ShotGroup)
	{
		LinkedHashSet lin_AllShots = new LinkedHashSet();
	//	if (m_ShotGroup==null) return null;
		Iterator ite_SubShotGroups = m_ShotGroup.getShotgroups().iterator();
		while(ite_SubShotGroups.hasNext())
		{
			lin_AllShots.addAll(getAllShots( (Shotgroup)ite_SubShotGroups.next() ) );
			
		}
		lin_AllShots.addAll( m_ShotGroup.getShots() );
		return lin_AllShots;
	}
	public String getAllShotsId(){
		LinkedHashSet lhs=getAllShots();
		StringBuffer sb=new StringBuffer();
		for(Iterator iter=lhs.iterator();iter.hasNext();){
			Shot shot=(Shot)iter.next();
			sb.append(shot.getShotId()).append(",");
		}
		return sb.toString();
	}
	public boolean isRoot() {
		return this.shotGroup.getShotgroup()==null ? true :false;
		
	}
	
}
